﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Jungle.Code.BLL;
using Jungle.Code.Utils;
using System.Collections.Generic;
using Jungle.Code.DAL;
using System.Data.SqlClient;

	public partial class users : UserControl
	{
        protected override void Render(HtmlTextWriter writer)
        {
            writer.AddAttribute(HtmlTextWriterAttribute.Bgcolor, "#ece9d8");
            writer.AddStyleAttribute(HtmlTextWriterStyle.BorderWidth, "15");
            writer.AddStyleAttribute(HtmlTextWriterStyle.BorderStyle, "solid");
            writer.AddStyleAttribute(HtmlTextWriterStyle.BorderColor, "#ece9d8");
            writer.RenderBeginTag(HtmlTextWriterTag.Table);
            writer.AddAttribute(HtmlTextWriterAttribute.Height, "20px");
            writer.AddAttribute(HtmlTextWriterAttribute.Valign, "top");
            writer.RenderBeginTag(HtmlTextWriterTag.Tr);
            writer.RenderBeginTag(HtmlTextWriterTag.Td);
                writer.Write("<strong>Список пользователей:</strong>");
            writer.RenderEndTag();
            writer.RenderEndTag();


            using (SqlConnection connect = new SqlConnection(DBHelper.ConnectionString))
            {
                SqlCommand command = new SqlCommand("mdUsers_GetAll", connect);
                SqlDataReader reader = null;
                command.CommandType = CommandType.StoredProcedure;

                command.Connection.Open();
                    reader = command.ExecuteReader();
                    while (reader.Read())
                    {
                        writer.AddAttribute(HtmlTextWriterAttribute.Height, "10px");
                        writer.AddAttribute(HtmlTextWriterAttribute.Valign, "top");
                        writer.RenderBeginTag(HtmlTextWriterTag.Tr);
                        writer.RenderBeginTag(HtmlTextWriterTag.Td);
                            writer.Write("&nbsp;&nbsp;&nbsp;");
                            writer.AddAttribute(HtmlTextWriterAttribute.Href, "Users.aspx?cmd=more&id_user=" + reader.GetValue(0));
                            writer.RenderBeginTag(HtmlTextWriterTag.A);
                                writer.AddAttribute(HtmlTextWriterAttribute.Src, "../Modules/UserManager/img/user.jpg");
                                writer.RenderBeginTag(HtmlTextWriterTag.Img);
                                writer.RenderEndTag();
                                writer.Write("&nbsp;");
                                writer.Write(reader.GetValue(1).ToString());
                            writer.RenderEndTag();
                        writer.RenderEndTag();
                        writer.RenderEndTag();
                    }
                command.Connection.Close();

            }

            writer.RenderEndTag();
            base.Render(writer);
        }
	}
